package com.fire.market.repository.impl;

import com.fire.component.extension.Assert;
import com.fire.market.entity.ItemDo;
import com.fire.market.mapper.ItemDoMapper;
import com.fire.market.repository.ItemRepository;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

@Repository
public class ItemRepositoryImpl implements ItemRepository {
    @Resource
    private ItemDoMapper itemDoMapper;
    @Override
    public List<ItemDo> selectAllItem() {
        return itemDoMapper.selectAll();
    }

    @Override
    public void insertItem(ItemDo itemDo) {
        Assert.notNull(itemDo, "itemDo is null");
        itemDoMapper.insertSelective(itemDo);
    }

    @Override
    public ItemDo selectItemById(Integer id) {
        Assert.notNull(id, "id is null");
        return itemDoMapper.selectByPrimaryKey(id);
    }

    @Override
    public void increaseSales(Integer itemId, Integer amount) {
        Assert.notNull(itemId, "itemId is null");
        Assert.notNull(amount, "amount is null");
        itemDoMapper.increaseSalesByItemId(itemId,amount);
    }

    @Override
    public void decreaseSales(Integer itemId, Integer amount) {
        Assert.notNull(itemId, "itemId is null");
        Assert.notNull(amount, "amount is null");
        itemDoMapper.decreaseSalesByItemId(itemId,amount);
    }
}
